package inherit;

class Base{
    int a;
    int b;

    public void methodA(int n){
        System.out.println("Base::methodA");
    }
}
public class Derived extends Base{
    int a;
    int c;
    public void method(){
        super.a = 10; //此时当父类和子类 都拥有 同名的变量 的时候，优先访问 子类自己
        b = 20;
        c = 30;
        System.out.println(super.a); //父类和子类重命时，强行打印父类的变量（supper）
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }

    public void methodA(){
        System.out.println("Derived::methodA");
    }
    public void methodB(){
        System.out.println("Derived::methodB");
    }
    public void methodC(){
//        methodA(); //访问自己的methodA()
        methodA(10); //访问父类的methodA()
        methodB(); //访问自己的methodB()
    }

    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.method();
        derived.methodC();

        /*Base base = new Base();
        System.out.println(base.a); //就近原则*/
    }
}
